<?php
// +----------------------------------------------------------------------
// | [RhaPHP System] Copyright (c) 2017 http://www.rhaphp.com/
// +----------------------------------------------------------------------
// | [RhaPHP] 并不是自由软件,你可免费使用,未经许可不能去掉RhaPHP相关版权
// +----------------------------------------------------------------------
// | Author: Geeson <qimengkeji@vip.qq.com>
// +----------------------------------------------------------------------


namespace addons\hlapp\model;

use addons\hlapp\controller\FileCache;
use addons\hlapp\dto\PageInfo;
use think\Db;
use think\helper\Arr;
use think\Log;
use think\Model;

class HlappProjectType extends CommonModel
{

    //项目阶段1对多
    public function stages(){
        return $this->hasMany('HlappTypeStage','type_id');
    }

    //分类列表
    public function getTypeList()
    {
        return $this->with('stages')->select();
    }

    /**
     * 从缓存获取项目分类
     * @return mixed
     * @throws \think\exception\DbException
     */
    public static function getProjectType(){
        $project_type_cache = CacheEnum::PROJECT_TYPE_CACHE;
        $cache = new FileCache();
        $part_info = $cache->get($project_type_cache);
        if (!$part_info){
            $typeCache = array();
            \Log::INFO("更新项目分类缓存");
            $part_info = HlappProjectType::all();
            foreach ($part_info as $val){
                $typeCache[$val['id']] = $val;
            }
            $cache->set($project_type_cache,$typeCache);
        }
        return $part_info;
    }
}